#include "TcpServer.hpp"
#include "Dict.hpp"
#include "Command.hpp"

std::string defaulthandler(const std::string &word, InetAddr &addr)
{
    std::string s = "haha, ";
    s += word;
    return s;
}

void Usage(std::string proc)
{
    std::cout << "Usage: " << proc << " port" << std::endl;
}

int main(int argc, char *argv[])
{
    Enable_Console_Log_Strategy();
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERR);
    }
    uint16_t port = std::stoi(argv[1]);

    // Dict d;
    // d.LoadDict();
    Command cmd;

    std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, [&cmd](const std::string &word, InetAddr &addr) -> std::string{
        return cmd.Execute(word, addr);
    });

    // std::unique_ptr<TcpServer> tsvr = std::make_unique<TcpServer>(port, [&d](const std::string &word, InetAddr &addr)->std::string{
    //     d.Translate(word, addr);
    //     return word;
    // });
    tsvr->Init();
    tsvr->Run();
    return 0;
}